<?php


namespace app\admin\controller;


use app\admin\model\AdminUser;
use think\facade\View;

class Admin extends AdminBase {
    public function accountEdit() {
        $data = (new AdminUser())->field('username,password')->find(1);
        if ($this->request->isGet()) {
            return View::fetch('', ['username' => $data['username']]);
        } else {
            $username = $this->request->post('username', '');
            $L_pass = $this->request->post('L_pass', '');
            $pass = $this->request->post('pass', '');
            $repass = $this->request->post('repass', '');
            if ($data['password'] != md5($L_pass . config('admin.md5_poke'))) {
                return show(config('status.error'), '旧密码不正确');
            }
            if ($pass != $repass) {
                return show(config('status.error'), '两次密码不一致');
            }
            $data->username = $username;
            $data->password = md5($pass . config('admin.md5_poke'));
            $data->update_time = time();
            $res = $data->save();
            if (!$res) {
                return show(config('status.error'), '修改账户失败');
            }
            return show(config('status.success'), '修改账户成功');
        }
    }

    public function login() {
        echo '登录';
    }
}